package com.ztf0337.mycurriculumdesign.service;

import android.content.Context;

import com.ztf0337.mycurriculumdesign.dao.ParkLotDao;
import com.ztf0337.mycurriculumdesign.dao.ParkingSpaceDao;
import com.ztf0337.mycurriculumdesign.database.AppDatabase;
import com.ztf0337.mycurriculumdesign.entity.ParkLot;

import java.util.List;

public class ParkLotService {

    private final ParkLotDao parkLotDao;
    public final ParkingSpaceDao parkingSpaceDao;
    public ParkLotService(Context context) {
        AppDatabase db = AppDatabase.getInstance(context);
        this.parkLotDao = db.parkLotDao();
        this.parkingSpaceDao = db.parkingSpaceDao();
    }

    public long inset(ParkLot parkLot) {
        return parkLotDao.insert(parkLot);
    }

    public void delete(ParkLot parkLot) {
        parkLotDao.delete(parkLot);
        parkingSpaceDao.deleteByLotId(parkLot.getId());
    }

    public void update(ParkLot parkLot) {
        parkLotDao.update(parkLot);
    }

    public List<ParkLot> getAllParkLot() {
        return parkLotDao.getAllParkLots();
    }

    public ParkLot getParkLotById(Long id) {
        return parkLotDao.getParkLotById(id);
    }

    public List<ParkLot> searchAllParkLots(String content) {
        return parkLotDao.searchAllParkLots(content);
    }


}
